package jmine.tec.security.ldap.connector;

import java.util.ArrayList;
import java.util.List;

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;

import org.apache.commons.lang.StringUtils;
import org.springframework.ldap.core.AttributesMapper;

/**
 * Mapeia atributos provenientes de um usuário.
 * Esta implementação traz todos os atributos encontrados. 
 * 
 * @author seiti
 * @created Apr 28, 2011
 */
public class UserMapper implements AttributesMapper {
    /**
     * {@inheritDoc}
     */
    public String mapFromAttributes(Attributes attributes) throws NamingException {
        List<String> attrs = new ArrayList<String>();
        NamingEnumeration<String> ids = attributes.getIDs();
        while (ids.hasMoreElements()) {
            String id = ids.nextElement();
            attrs.add(String.format("[%s : %s]", id, attributes.get(id)));
        }
        return StringUtils.join(attrs, ", ");
    }
}